package pro.fraud_detect.config;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

/***
 * @author hunter.d
 * @qq 657270652
 * @wx haitao-duan
 * @date 2021/2/22
 **/
public class Config {

    private final HashMap<Param<?>,Object> values = new HashMap<>();
    public <T> void put(Param<T> param,T value){
        values.put(param,value);
    }

    public <T> T get(Param<T> param){
        return param.getType().cast(values.get(param));

    }

    public Config(Parameters parameters, List<Param<String>> stringParams,List<Param<Boolean>> boolParams, List<Param<Integer>> intParams){
        overrideDefaults(parameters, stringParams);
        overrideDefaults(parameters, intParams);
        overrideDefaults(parameters, boolParams);
    }

    public static Config fromParameters(Parameters parameters){
        return new Config(parameters,Parameters.STRING_PARAMS,Parameters.BOOL_PARAMS,Parameters.INT_PARAMS);
    }

    private <T> void overrideDefaults(Parameters parameters,List<Param<T>> params){
        for (Param<T> param : params) {
            values.put(param,parameters.getOrdefault(param));
        }
    }

}
